package com.sluggard.mp.model.req;

import com.sluggard.mp.model.enums.OperatorEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;


@Data
@Schema(name = "查询条件",description = "查询条件")
public class SearchParam {

    @NotBlank(message = "字段名不能为空")
    @Schema(description = "字段名", requiredMode = Schema.RequiredMode.REQUIRED)
    private String column;

    @NotNull(message = "操作符不能为空")
    @Schema(description = "操作符", requiredMode = Schema.RequiredMode.REQUIRED)
    private OperatorEnum operator;

    @Schema(description = "查询值", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    private Object value;

    @Schema(description = "最大值(BETWEEN,NOT_BETWEEN适用)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    private Object min;

    @Schema(description = "最小值(BETWEEN,NOT_BETWEEN适用)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    private Object max;

    public String getColumn() {
        // 驼峰转下划线
        return column.replaceAll("[A-Z]", "_$0").toLowerCase();
    }
}
